package cn.stylefeng.guns.modular.goods.info.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goods.info.entity.Info;
import cn.stylefeng.guns.modular.goods.info.model.params.InfoParam;
import cn.stylefeng.guns.modular.goods.info.model.result.InfoResult;
import cn.stylefeng.guns.modular.goods.info.service.InfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 控制器
 *
 * @author SYT
 * @Date 2020-10-13 16:48:50
 */
@Controller
@RequestMapping("/info")
public class InfoController extends BaseController {

    private String PREFIX = "/goods";

    @Autowired
    private InfoService infoService;

    /**
     * 跳转到主页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("")
    public String index(int classification) {
        if(classification == 1){
            return PREFIX + "/blade/blade.html";
        }else if(classification == 2){
            return PREFIX + "/hilt/hilt.html";
        }else if(classification==3){
            return PREFIX + "/materiel/materiel.html";
        }
        else {
            return null;
        }
    }

    /**
     * 新增页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/add")
    public String add(int classification) {
        if(classification == 1){
            return PREFIX + "/blade/blade_add.html";
        }else if(classification == 2){
            return PREFIX + "/hilt/hilt_add.html";
        }else if(classification==3){
            return PREFIX + "/materiel/materiel_add.html";
        }else {
            return null;
        }
    }

    /**
     * 编辑页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/edit")
    public String edit(int classification) {
        if(classification == 1){
            return PREFIX + "/blade/blade_edit.html";
        }else if(classification == 2){
            return PREFIX + "/hilt/hilt_edit.html";
        }else if(classification==3){
            return PREFIX + "/materiel/materiel_edit.html";
        }else {
            return null;
        }
    }

    @RequestMapping("/details")
    public String details(int classification) {
        if(classification == 1){
            return PREFIX + "/blade/blade_details.html";
        }else if(classification == 2){
            return PREFIX + "/hilt/hilt_details.html";
        }else if(classification==3){
            return PREFIX + "/materiel/materiel_details.html";
        }else {
            return null;
        }
    }

    /**
     * 新增接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(InfoParam infoParam) {
        this.infoService.add(infoParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(InfoParam infoParam) {
        this.infoService.update(infoParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(InfoParam infoParam) {
        this.infoService.delete(infoParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(InfoParam infoParam) {
        Info detail = this.infoService.getById(infoParam.getGoodsId());
        return ResponseData.success(detail);
    }

    @RequestMapping("/getone")
    @ResponseBody
    public ResponseData getone(InfoParam infoParam) {
        InfoResult detail = this.infoService.getOneByID(infoParam.getGoodsId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(InfoParam infoParam) {
        return this.infoService.findPageBySpec(infoParam);
    }

}


